package abd.pr1.Mappers;


import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.sql.DataSource;




import abd.pr1.Models.ComentarioSerie;

public class ComentariosSeriesMapper extends AbstractMapper<ComentarioSerie, Integer> {

	private static final String[] COMENTARIOSSERIES_KEY_COLUMN_NAMES = new String[] { "id" };
	private static final String[] COMENTARIOSSERIES_COLUMN_NAMES = new String[] { "id","id_usuario", "id_serie",  "texto", "fecha"};
	private static final String COMENTARIOSSERIES_TABLE_NAME = "comentarios_series";
	
	public ComentariosSeriesMapper(DataSource ds) {
		super(ds);
	}
	
	@Override
	protected String getTableName() {
		return COMENTARIOSSERIES_TABLE_NAME;
	}

	@Override
	protected String[] getColumnNames() {
		return COMENTARIOSSERIES_COLUMN_NAMES;
	}

	@Override
	protected Object[] serializeObject(ComentarioSerie object) {
		return new Object[] { object.getId(),object.getId_usuario(), object.getId_serie(),  object.getTexto(),object.getFecha()};
	}

	@Override
	protected String[] getKeyColumnNames() {
		return COMENTARIOSSERIES_KEY_COLUMN_NAMES;
	}

	@Override
	protected Object[] serializeKey(Integer key) {
		return new Object[] { key };
	}

	@Override
	protected ComentarioSerie buildObject(ResultSet rs) throws SQLException {
		Integer id = rs.getInt("id");
		String texto = rs.getString("texto");
		Date fecha = rs.getDate("fecha");
		Integer id_serie = rs.getInt("id_serie");
		Integer id_usuario = rs.getInt("id_usuario");
		return new ComentarioSerie(id, id_usuario, id_serie, texto, fecha);
	}

	@Override
	protected Integer getKey(ComentarioSerie object) {
		return object.getId();
	}

	@Override
	protected boolean hasAutoincrementKey() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	void updateKeys(ResultSet rs, ComentarioSerie object) throws SQLException {
		Integer id = rs.getInt(1);
		object.setId(id);	
		
	}
	
	
}
